window.$$TreeGridUtils = dfp.TreeGridUtils = {
}

/**
 * 重新加载数据
 * ①rtdata 不报错，一般是id给错了
 * ②
 * @param url 接口
 * @param queryParam 查询条件 比如：let queryParams = $.extend(page.getQueryParams(),{noteStatus:pageParam.noteStatus,query:true});
 * @param id getElementById
 */
$$TreeGridUtils.reload = function (url,queryParams,id) {
    var rtdata = dfp.utils.ajaxPost(url, queryParams);
    if(rtdata && rtdata.rows){
        $("#" + id).treegrid("loadData",rtdata);
    }
}

$$TreeGridUtils.getData = function (id) {
    let grid = $("#" + id);
    let rows = grid.treegrid("getData");
    return rows;
}




$$TreeGridUtils.getSelectionsByCK = function (id) {
    let selectionRows = new Array();
    let rows = $$TreeGridUtils.getData(id);
    for (let i = 0; i < rows.length; i++) {
        let row = rows[i];
        if(row["ck"] == "1" ){
            selectionRows.push(row);
        }
    }
    return selectionRows;
}

// ----------------------------------------------------审计系统，整改通知----------------------------------------------------

$$TreeGridUtils.getDataNotice = function (id) {
    let grid = $("#" + id);
    let rows = grid.treegrid("getData");
    let realRows = new Array();
    $$TreeGridUtils.addChildren(rows,realRows);
    return realRows;
}

$$TreeGridUtils.addChildren = function(rows,realRows){
    if(rows.length <= 0){
        return;
    }
    for (let i = 0; i < rows.length; i++) {
        let row = rows[i];
        realRows.push(row);
        if(row.children && row.children.length > 0){
            $$TreeGridUtils.addChildren(row.children,realRows);
        }
    }
}

/**
 * 专门给审计系统的整改通知做的
 * @param id
 * @returns {any[]}
 */
$$TreeGridUtils.getSelectionsByCKNotice = function (id,isSelectAll) {
    let selectionRows = new Array();
    let rows = $$TreeGridUtils.getDataNotice(id);
    for (let i = 0; i < rows.length; i++) {
        let row = rows[i];
        // 未下达 再校验一下保险一点
        // ①全选的时候没有ck
        if(isSelectAll == true){
            if(row["has_last"] == "是" && row["status"] == "未下达"){
                selectionRows.push(row);
            }
        }else {
            if(row["ck"] == "1" && row["has_last"] == "是" && row["status"] == "未下达"){
                selectionRows.push(row);
            }
        }
    }
    return selectionRows;
}

